#include<iostream>
#include <string>
using namespace std;


class Student
{
public:  // 静态数据成员要放在公有部分
static int average;
protected:
    string num, name;
public:
    Student(string numm, string namee)
    {   
        num = numm;
        name = namee;
    }
    virtual void display() = 0;
}; int Student::average = 0;

class GroupA: public Student
{
protected:
    int s1, s2;
 int ave;
public:
    GroupA(string num, string name, int ss1, int ss2):Student(num, name)
    {

        s1 = ss1;
        s2 = ss2;
        ave = int(s1) + int(s2);
        ave /= 2;
        if(ave > Student::average)
        {
            Student::average = ave;
        }
    }
    void display()
    {   
        if(ave >= Student::average) cout << num << " " << name << endl;
    }
};


class GroupB: public Student
{
protected:
    int s1, s2;
    char gs;
 int ave;
public:
    GroupB(string num, string name, int ss1, int ss2, char c):Student(num, name)
    {
        s1 = ss1;
        s2 = ss2;
        gs = c;
        ave = int(s1) + int(s2);
        ave /= 2;
        if(ave > Student::average)
        {
            Student::average = ave;
        }
    }
    void display()
    {
        // 充分理解题意
        if(ave >= Student::average*0.7 && gs == 'A') cout << num << " " << name << endl;
        else if(ave >= Student::average) cout << num << " " << name << endl;
    }
};


class GroupC: public Student
{
protected:
    int s1, s2, s3, s4, s5;
 int ave;
public:
    GroupC(string num, string name, int ss1, int ss2, int ss3, int ss4, int ss5):Student(num, name)
    {
        s1 = ss1;
        s2 = ss2;
        s3 = ss3;
        s4 = ss4;
        s5 = ss5;
        ave = int(s1+s2+s3+s4+s5)/5;
    }
    void display()
    {
        if(ave >= Student::average*0.9) cout << num << " " << name << endl;
    }
};


int main()
{
    const int Size=50;
    string num, name;
    int i,ty,s1,s2,s3,s4,s5;
    char gs;
    Student *pS[Size];
    int count=0;
    for(i=0;i<Size;i++){
        cin>>ty;
        if(ty==0) break;
        cin>>num>>name>>s1>>s2;
        switch(ty){
             case 1:pS[count++]=new GroupA(num, name, s1, s2); break;
             case 2:cin>>gs; pS[count++]=new GroupB(num, name, s1,s2, gs); break;
             case 3:cin>>s3>>s4>>s5; pS[count++]=new GroupC(num, name, s1,s2,s3,s4,s5); break;
        }            
    }
    for(i=0;i<count;i++) {
        pS[i]->display();
        delete pS[i];
    }
    return 0;
}